package com.nettm.leetcode;

public class PalindromeNumber009 {

    public static void main(String[] args) {
        System.out.println(PalindromeNumber009.isPalindrome(-2147447412));
    }

    public static boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }

        int result = 0;
        int tmp = x;
        while (tmp != 0) {
            if (result > Integer.MAX_VALUE / 10 || result < Integer.MIN_VALUE / 10) {
                result = 0;
                break;
            }

            result *= 10;
            int a = tmp / 10;
            int b = tmp % 10;
            tmp = a;
            result += b;
        }

        return x == result;
    }

}
